#案例：一个简版的接口自动化测试！

#需求：POST http://shop.aircheng.com/simple/login_act
#         form: login_info=nswe&password=111111

import requests
from bs4 import BeautifulSoup #导入bs4库


fp=open("data/data_login.txt",mode="r")
for line in fp:
    line=line.strip()
    t=line.split(",")

    #拿到业务数据和预期结果
    zanhao=t[0]
    pwd=t[1]
    yuqi=t[2]

    #发请求
    data=\
    {
        "login_info":zanhao,
        "password":pwd
    }
    r=requests.post(url="http://shop.aircheng.com/simple/login_act",data=data)
    #获取响应实体html
    response_body=r.text
    #从响应实体中拿到实际
    soup = BeautifulSoup(response_body, 'lxml');
    eles_h2 = soup.select("body > div.center_content > section.web > div > section > section.uc_info > div.user_info > h2")
    ele_yonhumin = eles_h2[0]

    # 获取文本内容来座位实际结果
    siji = str(ele_yonhumin.string)

    # 断言：预期结果和实际结果
    if yuqi == siji:
        print("成功")
    else:
        print("失败")

fp.close()